package demo08

/**
 * @author xiaoZhao
 * @date 2022/8/8
 * @describe 泛型
 */
object Test03_Generics {
  def main(args: Array[String]): Unit = {
    // 1.协变和逆变
    val child: Parent = new Child
    val childList: MyCollection[Parent] =new MyCollection[Child]
//    val childList1: MyCollection[SubChild] =new MyCollection[Child]

    // 2.上下限
    def test[A <:Child](a: A)={
      println(a.getClass.getName)
    }

    test[Child](new Child)
    test[SubChild](new SubChild)
    test[Child](new SubChild)
  }
}

class Parent{}
class Child extends Parent{}
class SubChild extends Child{}

// 定义带泛型的集合类型
class MyCollection[+E] {}